<?php
namespace app\system\controller;

use app\common\model\UserModel;
use app\common\model\UserSiteModel;
use think\Request;

class ReachController extends BaseController
{

    private $userSiteModel;
    private $userModel;

    /**
     * 初始化
     */
    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->userSiteModel = new UserSiteModel();
        $this->userModel = new UserModel();
    }

    /**
     * 字典首页
     * @return mixed
     */
    public function upSite()
    {
        $query = [];
        $list = $this->userSiteModel->upSiteModel($this->getSiteId())->paginate(12,false,['query'=>$query]);
        $this->assign('list',$list);
        return $this->fetch();
    }

   public function downSite(){
       $query = [];
       $list = $this->userSiteModel->downSiteModel($this->getSiteId())->paginate(12,false,['query'=>$query]);
       $this->assign('list',$list);
       return $this->fetch();
   }

    public function edit(){
        $data = $this->request->param();
        if($data['status'] == 0){
            $data['status'] = 1;
        }else{
            $data['status'] = 0;
        }
        $this->userModel->where('site_id',$this->getSiteId())->where('uid',$data['uid'])->setField('status',$data['status']);
        $this->success('修改成功！',url('downSite'));
    }

    public function del(){
        $uid = $this->request->param();
        $this->userModel->delData($uid);
        $this->success('取消关注成功！',url('upSite'));
    }
}
